/*
 * @Author: Evanxu-home evanxu8023@163.com
 * @Date: 2025-10-23 23:38:32
 * @LastEditors: Evanxu-home evanxu8023@163.com
 * @LastEditTime: 2025-11-06 22:06:31
 * @FilePath: \program\hardware\lcd.h
 * @Description: 
 *  xxx 
 * Copyright (c) 2025 by ${git_name_email}, All Rights Reserved. 
 */
#ifndef lcd_h
#define lcd_h

/* 包含头文件 ----------------------------------------------------------------*/
#include "sys.h"
#include "define.h"
#include "drv_spi.h"
//#include "drv_delay.h"

/* 类型定义 ------------------------------------------------------------------*/

#define USE_HW_SPI			//使用硬件SPI

#ifndef USE_HW_SPI
	#define USE_SF_SPI 		//使用软件模拟SPI
#endif



//SCK
#define LCD_SCK_PIN					GPIO_PINS_5
#define LCD_SCK_GPIO				GPIOA
#define LCD_SCK_GPIO_CRM_CLK		(crm_periph_clock_type)CRM_GPIOA_PERIPH_CLOCK
#define LCD_SCK_H					(LCD_SCK_GPIO->scr = LCD_SCK_PIN)
#define LCD_SCK_L					(LCD_SCK_GPIO->clr = LCD_SCK_PIN)
//SDA
#define LCD_MOSI_PIN				GPIO_PINS_7
#define LCD_MOSI_GPIO				GPIOA
#define LCD_MOSI_GPIO_CRM_CLK		(crm_periph_clock_type)CRM_GPIOA_PERIPH_CLOCK
#define LCD_MOSI_H					(LCD_MOSI_GPIO->scr = LCD_MOSI_PIN)
#define LCD_MOSI_L					(LCD_MOSI_GPIO->clr = LCD_MOSI_PIN)
//SDO
//#define LCD_MISO_PIN				GPIO_PINS_3
//#define LCD_MISO_GPIO				GPIOA
//#define LCD_MISO_GPIO_CRM_CLK		(crm_periph_clock_type)CRM_GPIOA_PERIPH_CLOCK
//#define LCD_MISO_H					(LCD_MISO_GPIO->scr = LCD_MISO_PIN)
//#define LCD_MISO_L					(LCD_MISO_GPIO->clr = LCD_MISO_PIN)
//CS
#define LCD_CS_PIN					GPIO_PINS_4
#define LCD_CS_GPIO					GPIOA
#define LCD_CS_GPIO_CRM_CLK			(crm_periph_clock_type)CRM_GPIOA_PERIPH_CLOCK
#define LCD_CS_H					(LCD_CS_GPIO->scr = LCD_CS_PIN)
#define LCD_CS_L					(LCD_CS_GPIO->clr = LCD_CS_PIN)
//DC
#define LCD_DC_PIN					GPIO_PINS_2
#define LCD_DC_GPIO					GPIOA
#define LCD_DC_GPIO_CRM_CLK			(crm_periph_clock_type)CRM_GPIOA_PERIPH_CLOCK
#define LCD_DC_H					(LCD_DC_GPIO->scr = LCD_DC_PIN)
#define LCD_DC_L					(LCD_DC_GPIO->clr = LCD_DC_PIN)
//BL
#define LCD_BL_PIN					GPIO_PINS_0
#define LCD_BL_GPIO					GPIOB
#define LCD_BL_GPIO_CRM_CLK			(crm_periph_clock_type)CRM_GPIOB_PERIPH_CLOCK
#define LCD_BL_ON					(LCD_BL_GPIO->scr = LCD_BL_PIN)
#define LCD_BL_OFF					(LCD_BL_GPIO->clr = LCD_BL_PIN)
//RST
#define LCD_RST_PIN					GPIO_PINS_3
#define LCD_RST_GPIO				GPIOA
#define LCD_RST_GPIO_CRM_CLK		(crm_periph_clock_type)CRM_GPIOA_PERIPH_CLOCK
#define LCD_RST_H					(LCD_RST_GPIO->scr = LCD_RST_PIN)
#define LCD_RST_L					(LCD_RST_GPIO->clr = LCD_RST_PIN)



#define LCD_X_MAX	160
#define LCD_Y_MAX	80

#define LCD_BACK_LIGHT_MAX  100

#define LCD_PWM_CYCLE		TIMER3_PWM_CYCLE
#define LCD_PWM_MIN			(TIMER3_PWM_CYCLE/10)


/* 函数声明 --------------------------------------------------------------------*/
void lcd_write_data(u8 o_data);
void lcd_write_cmd(u8 o_command);
void lcd_write_halfword(u16 o_data);
void lcd_write_n_data(u8 *o_data, u16 n);
void lcd_set_address(u16 x1, u16 y1, u16 x2, u16 y2);


void lcd_init(void);
void lcd_clear(u16 color);
void lcd_full(u16 color);

void lcd_back_light_set(u8 val);
void lcd_draw_point(u16 x, u16 y, u16 color);


#endif


